import numpy
import math
import scipy
import scipy.io
import scipy.misc
import scipy.cluster
import scipy.cluster.vq
import matplotlib
import matplotlib.pyplot
import os
import IPython
import IPython.parallel
import itertools
import random
import sklearn
import sklearn.decomposition
import sklearn.manifold
import sklearn.cluster
import sklearn.feature_extraction
import sklearn.feature_extraction.text
base_path = "/u/mlrobert/code/local/2013_drawing_assistant/data/"
filter_path = base_path+"/filters/gabor/num_thetas=08/"
debug_path = base_path+"/debug/filters/gabor/num_thetas=08/"
if not os.path.exists(filter_path):
os.makedirs(filter_path)
if not os.path.exists(debug_path):
os.makedirs(debug_path)
side_length = 512
line_width = 0.02
lamb = 0.2
w = 0.13
sigma_x = line_width * w
sigma_y = sigma_x / lamb
num_thetas = 8
thetas = numpy.linspace(0, math.pi, num_thetas + 1)
for theta_index in range(num_thetas):
theta = thetas[theta_index]
R = numpy.array([[math.cos(theta), -math.sin(theta)], [math.sin(theta), math.cos(theta)]])
u = numpy.arange(-256, 256)
v = numpy.arange(-256, 256)
(U, V) = numpy.meshgrid(u, v)
U_theta = (U * R[0,0]) + (V * R[0,1])
V_theta = (U * R[1,0]) + (V * R[1,1])
g = numpy.exp(-2*(math.pi**2)*((U_theta - w)**2*(sigma_x**2) + (V_theta**2)*(sigma_y**2)))
scipy.io.savemat("%stheta=%02d.mat" % (filter_path, theta_index), {"g":g}, oned_as="column")
clf();
imshow(g, interpolation="nearest");
colorbar();
savefig("%stheta=%02d.png" % (debug_path, theta_index));
clf();